package business.inhospitalqc;

import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.yamlbeans.YamlException;
import common.Data;
import common.RunCaseJson;
import common.Yaml;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import utils.GetFileMess;
import utils.YamlReadUtil;

import java.io.FileNotFoundException;

import static common.Login.login;
import static common.TestStep.requestAndRespondBody;

/**
 * @ProjectName: ApiAutotest
 * @Package: business.inhospitalqc
 * @ClassName: TableCreate
 * @Author: Administrator
 * @Description: 填写质量管理医院自我评价表
 * @Date: 2021-08-24 15:50
 * @Version: 1.0
 */
public class TableCreate {
    Logger log = Logger.getLogger(TableCreate.class);
    public static final String system = "env.properties";
    Data data = login();

    public  String  createTable(int i,String visitDate,String indexTime,String aDays,String age,String inpatientNo,String id,String batchId,String qcCheckOption) throws FileNotFoundException, ConfigurationException, YamlException {
        String path=new GetFileMess().getValue("ymlPath",system);
        Yaml yaml= YamlReadUtil.getLocatorMap(path,this.getClass().getName());
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("diseaseCode", yaml.getDatas().get(i).get("diseaseCode"));
        json.put("totalCosts", yaml.getDatas().get(i).get("totalCosts"));      //住院总花费
        json.put("totalCostsMedical", yaml.getDatas().get(i).get("totalCostsMedical"));   //医药费
        json.put("useTrace", yaml.getDatas().get(i).get("useTrace"));  //
        json.put("isCopd", yaml.getDatas().get(i).get("isCopd"));      //是否有COPD的症状  1：是，
        json.put("isExposureObviousStimuli", yaml.getDatas().get(i).get("isExposureObviousStimuli"));   //有显著有害刺激物暴露
        json.put("isValueSevenAfterBron", yaml.getDatas().get(i).get("isValueSevenAfterBron"));  // 使用支气管舒张剂后FEV1/F VC<0.7
        json.put("copdGrade", yaml.getDatas().get(i).get("copdGrade"));   //COPD的临床严重程度分级   1：1级
        json.put("oxygenCheckIn24hHosp", yaml.getDatas().get(i).get("oxygenCheckIn24hHosp"));   //入院24H内氧合评估
        json.put("criteriaInHosp", yaml.getDatas().get(i).get("criteriaInHosp"));      //收住院符合指征
        json.put("criteriaInIcu", yaml.getDatas().get(i).get("criteriaInIcu"));     //收住ICU符合指征
        json.put("oxygenNasalTube", yaml.getDatas().get(i).get("oxygenNasalTube"));    //应用鼻导管吸氧（氧疗）
        json.put("oxygenBloodAnalyze", yaml.getDatas().get(i).get("oxygenBloodAnalyze"));           //氧疗后复查动脉血气分析
        json.put("oxygenMask", yaml.getDatas().get(i).get("oxygenMask"));           //应用面罩吸氧（氧疗）
        json.put("oxygenVentilator", yaml.getDatas().get(i).get("oxygenVentilator"));       //应用呼吸机（氧疗）
        json.put("oxygenInLine", yaml.getDatas().get(i).get("oxygenInLine"));       //符合指征(氧疗方法应用)
        /*起始抗菌药物选择与应用适当  1:轻度及中度COPD急性加重;2:重度及极重度COPD急性加重，无铜绿假单胞菌、耐甲氧西林金葡菌和感染危险因素;3:重度及极重度COPD急性加重，有铜绿假单胞菌、耐甲氧西林金葡菌和感染危险因素;4:N/A
         */
        json.put("antiAgentOption", yaml.getDatas().get(i).get("antiAgentOption"));
        json.put("antiAgentLevel", yaml.getDatas().get(i).get("antiAgentLevel"));  //起始抗菌药物选择与应用适当（程度）

        json.put("bronOption", yaml.getDatas().get(i).get("bronOption"));       //选择支气管舒张剂应用
        json.put("sysGluOption", yaml.getDatas().get(i).get("sysGluOption"));       //选择糖皮质激素全身应用
        json.put("cardiacInsuff", yaml.getDatas().get(i).get("cardiacInsuff"));         // 心功能不全
        json.put("caseOneComplication", yaml.getDatas().get(i).get("caseOneComplication"));     // 心功能不全药物
        json.put("pulmonaryHyper", yaml.getDatas().get(i).get("pulmonaryHyper"));       //肺动脉高压
        json.put("caseTwoComplication", yaml.getDatas().get(i).get("caseTwoComplication"));     //肺动脉高压药物
        json.put("thrombolyTherapy", yaml.getDatas().get(i).get("thrombolyTherapy"));       //肺栓塞
        json.put("caseThreeComplication", yaml.getDatas().get(i).get("caseThreeComplication"));     //肺栓塞药物
        json.put("respiratory17", yaml.getDatas().get(i).get("respiratory17"));     //呼吸衰竭
        json.put("caseFourComplication", yaml.getDatas().get(i).get("caseFourComplication"));       //呼吸衰竭药物
        json.put("comPneu", yaml.getDatas().get(i).get("comPneu"));         //气胸
        json.put("caseFiveComplication", yaml.getDatas().get(i).get("caseFiveComplication"));       //气胸药物
        json.put("noniVent", yaml.getDatas().get(i).get("noniVent"));       //无创通气治疗
        json.put("invaVent", yaml.getDatas().get(i).get("invaVent"));       //有创通气治疗
        json.put("invaNoniVent", yaml.getDatas().get(i).get("invaNoniVent"));       //有创-无创序贯通气治疗
        json.put("eduQuitSmokeCounsel", yaml.getDatas().get(i).get("eduQuitSmokeCounsel"));     //"戒烟咨询：-1=不抽烟，0=否，1=是(健康教育服务)
        json.put("eduReduceHazards", yaml.getDatas().get(i).get("eduReduceHazards"));       //减少危险因素(健康教育服务)
        json.put("eduDiseaseSelfControl", yaml.getDatas().get(i).get("eduDiseaseSelfControl"));     //疾病自我管理(健康教育服务)
        json.put("eduLungRehabilitation", yaml.getDatas().get(i).get("eduLungRehabilitation"));     //肺康复
        json.put("eduVaccination", yaml.getDatas().get(i).get("eduVaccination"));       //疫苗接种(健康教育服务)
        json.put("eduOtherHealth", yaml.getDatas().get(i).get("eduOtherHealth"));       //其他健康教育服务
        json.put("revisitingOneMonth", yaml.getDatas().get(i).get("revisitingOneMonth"));       //要求1月内复诊
        json.put("leaveHosMode", yaml.getDatas().get(i).get("leaveHosMode"));       //离院方式
        json.put("type", yaml.getDatas().get(i).get("type"));           //

        //下面是tasklist传过来的参数
        json.put("inpatientNo",inpatientNo );       //  病患No
        json.put("visitDate",visitDate );        //入院日期
        json.put("indexTime", indexTime);        //出院日期
        json.put("aDays", aDays);            //住院天数
        json.put("age", age);              //年龄
        json.put("qcCheckOption", qcCheckOption);    //质量管理措施项目（1-6级）
        json.put("id",id );           //id
        json.put("batchId",batchId );      //批量ID
        log.info("请求参数：" + json.toString());
        Response response = RunCaseJson.runCase(json, "post", yaml.getUri());
        String jsonStr = response.asString();
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath +  yaml.getUri();
        requestAndRespondBody(url,json,jsonStr);
        log.info("响应报文：" + jsonStr);

        return jsonStr;


    }

    /*
     *
     * @Description: 增加comment
     * @param serviceIdOne
     * @param serviceIdTwo
     * @return void
     * @author gujinle
     * @date 2021-08-25 17:56
     */
    public  void auditcommit(String serviceIdOne,String serviceIdTwo){

        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("serviceIdOne",serviceIdOne);
        json.put("serviceIdTwo",serviceIdTwo);
        log.info("请求参数：" + json.toString());
        Response response = RunCaseJson.runCase(json, "post", "api-project/opinion/auditcommit");
        String jsonStr = response.asString();
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath +  "api-project/opinion/auditcommit";
        requestAndRespondBody(url,json,jsonStr);
        log.info("响应报文：" + jsonStr);
    }

    /*
    *
    * @Description: 创建评审审核
     * @param id
     * @param content
    * @return void
    * @author gujinle
    * @date 2021-08-25 17:57
    */
    public  String checkCreate(String id,String content) {

        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("id",id);
        json.put("content",content);
        log.info("请求参数：" + json.toString());
        Response response = RunCaseJson.runCase(json, "post", "api-sourcedata/qc/check/create.json");
        String jsonStr = response.asString();
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath +  "api-sourcedata/qc/check/create.json";
        requestAndRespondBody(url,json,jsonStr);
        log.info("响应报文：" + jsonStr);

        return jsonStr;
    }
}
